#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target)
    {
        int left = 0, m = matrix.size(), n = matrix[0].size();
        int right = m * n - 1;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (matrix[mid / n][mid % n] < target)
            {
                left = mid + 1;
            }
            else
            {
                right = mid;
            }
        }
        if (matrix[left / n][left % n] == target)
        {
            return true;
        }
        return false;

    }
};

//////////////////////////////
class Solution {
public:
    int findMin(vector<int>& nums)
    {
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] > nums[nums.size() - 1])
            {
                left = mid + 1;
            }
            else
            {
                right = mid;
            }
        }
        return nums[left];
    }
};